package com.hz.ruoyiequipment.data.service.impl;

import com.hz.ruoyiequipment.data.domain.vo.SoilEquipment;
import com.hz.ruoyiequipment.data.domain.vo.SoilTimeData;
import com.hz.ruoyiequipment.data.mapper.AgrEquipmentMapper;
import com.hz.ruoyiequipment.data.mapper.AgrEquipmentTrMapper;
import com.hz.ruoyiequipment.data.service.AgrEquipmentTrService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: xqd
 * @CreateDate: 2025/03/08/9:24
 * @Description:
 */
@Service
public class AgrEquipmentTrServiceImpl implements AgrEquipmentTrService {
    @Autowired
    private AgrEquipmentTrMapper agrEquipmentTrMapper;
    @Autowired
    private AgrEquipmentMapper agrEquipmentMapper;

    @Override
    public AjaxResult getSoilTimeData(Long equipmentId) {
        SoilTimeData soilTimeData = agrEquipmentTrMapper.getSoilTimeData(equipmentId);

        return AjaxResult.success(soilTimeData);
    }


    @Override
    public AjaxResult getSoilTimeDatas(Long equipmentId) {

        return AjaxResult.success(agrEquipmentTrMapper.getSoilTimeDatas(equipmentId));
    }

    @Override
    public AjaxResult getSoilTimeDataHead(Long equipmentId) {
        return AjaxResult.success(agrEquipmentTrMapper.getSoilTimeDataHead(equipmentId));
    }

    @Override
    @Transactional
    public AjaxResult updateAgrEquipmentTr(SoilEquipment soilEquipment) {
        agrEquipmentTrMapper.updateAgrEquipmentTr(soilEquipment);
        agrEquipmentMapper.updateAgrEquipment(soilEquipment);
        Integer equipmentId = agrEquipmentTrMapper.getEquipmentId(soilEquipment.getEquipmentId());
        if (equipmentId == null) {
            if (soilEquipment.getPlotsId() != null) {
                agrEquipmentTrMapper.insertAgrEquipmentPlot(soilEquipment);
            }
        } else {
            agrEquipmentTrMapper.updateAgrEquipmentPlot(soilEquipment);
        }
        return AjaxResult.success();
    }

    @Override
    @Transactional
    public AjaxResult delAgrEquipmentTrByEquipmentId(Long equipmentId) {
        agrEquipmentMapper.delAgrEquipmentByEquipmentId(equipmentId);
        agrEquipmentTrMapper.delAgrEquipmentTrByEquipmentId(equipmentId);
        agrEquipmentTrMapper.delAgrEquipmentPlotByEquipmentId(equipmentId);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult insertSoilTimeData(SoilTimeData soilTimeData) {
        agrEquipmentTrMapper.insertSoilTimeData(soilTimeData);
        return AjaxResult.success();
    }





}
